﻿/*
   绑定视图：MenuView.xaml
   文件说明：菜单管理业务层
*/

using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using ZFSData;
using ZFSData.InterFace.User;
using ZFSDomain.Common.CoreLib;
using ZFSDomain.Interface.User;
using ZFSDomain.Service;
using ZFSDomain.SysModule;

namespace ZFSDomain.ViewModel.Menu
{

   
    public class MenuViewModel : BaseOperation<tb_Menu>
    {
        public override void GetPageData(int pageIndex)
        {
            try
            {
                IMenu user = ZFSBridge.BridgeFactory.GetMenuBridge();

                Expression<Func<tb_Menu, bool>> where = u => u.MenuCode.Contains(this.SearchText) || u.MenuName.Contains(this.SearchText);
                Expression<Func<tb_Menu, int>> order = u => u.isid;

                var MenuList = user.GetPagingModels(pageIndex, PageSize, out int total, where, order);
                TotalCount = total;
                GridModelList.Clear();
                MenuList.ForEach((arg) => GridModelList.Add(arg));
                base.SetPageCount();

            }
            catch (Exception ex)
            {
                Msg.Error(ex.Message);
            }
        }

        /// <summary>
        /// 绑定默认功能
        /// </summary>
        public override void SetDefaultButton()
        {
            ButtonDefaults = new System.Collections.ObjectModel.ObservableCollection<ToolBarDefault<tb_Menu>>();
            ButtonDefaults.Add(new ToolBarDefault<tb_Menu>() { AuthValue = Authority.IMPORT, ModuleName = "导入", Command = this.ImportCommand });
        }

        /// <summary>
        /// 导入菜单
        /// </summary>
        public void Import(object obj)
        {
            try
            {
                var Imenu = ServiceProvider.Instance.Get<IMenuDialog>();
                Imenu.BindViewModel(new MenuDialogViewModel());
                Imenu.ShowDialog();
            }
            catch (Exception ex)
            {
                Msg.Error(ex.Message);
            }

        }

        #region Command

        private RelayCommand<tb_Menu> _importCommand;

        public RelayCommand<tb_Menu> ImportCommand
        {
            get
            {
                if (_importCommand == null)
                {
                    _importCommand = new RelayCommand<tb_Menu>(t => Import(t));
                }
                return _importCommand;
            }
            set { _importCommand = value; }
        }

        #endregion
        
        #region Override

        public override void Add<TModel>(TModel model)
        {
            throw new NotImplementedException();
        }

        public override void Edit<TModel>(TModel model)
        {
            throw new NotImplementedException();
        }

        public override void Del<TModel>(TModel model)
        {
            throw new NotImplementedException();
        }

        #endregion

      
    }
}
